package com.demo.configuration;

import com.demo.configuration.TraceFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FilerConfiguration {
    /**
     * 登录过滤器
     *
     * @return FilterRegistrationBean
     */
    @Bean("traceFilter")
    public FilterRegistrationBean<TraceFilter> loginFilter() {
        FilterRegistrationBean<TraceFilter> filterRegistrationBean = new FilterRegistrationBean<>();
        TraceFilter traceFilter = new TraceFilter();

        filterRegistrationBean.setFilter(traceFilter);
        // 配置过滤规则
        filterRegistrationBean.addUrlPatterns("/*");
        // 设置过滤器名称
        filterRegistrationBean.setName("traceFilter");
        //执行次序
        filterRegistrationBean.setOrder(1);

        return filterRegistrationBean;
    }
}